<template>
  <div>
    <div class="bg-white grid-content">
      <div style="overflow: hidden">
        <div class="mytitle">
          <svg-icon icon-class="yjbb" class="myIcon" />数字化注入井生产日报
        </div>
        <div class="myButtons">
          <el-button
            @click="handleClick('', 'add')"
            v-if="hasPermission('sys:sjtb:dzyj:szhzrjscrbsj:add')"
            >新增</el-button
          >

          <el-button icon="el-icon-download" @click="handleDownload"
            >下载模板</el-button
          >
          <el-button
            class="import-button"
            icon="el-icon-upload2"
            @click="uploadFiles"
            v-if="hasPermission('sys:sjtb:dzyj:szhzrjscrbsj:import')"
            ><i class="icon"></i>批量导入</el-button
          >
          <el-dialog
            title="批量导入"
            :visible.sync="importDialog"
            class="dialog-md"
            width="500px"
            :before-close="handleClose1"
          >
            <el-form
              ref="fileForm"
              label-position="center"
              style="width: 100%"
              enctype="multipart/form-data"
            >
              <el-form-item align="center" label="">
                <el-upload
                  ref="upload"
                  class="uploadDialog"
                  name="myfile"
                  action="string"
                  :http-request="httpRequest"
                  :on-change="handleChange"
                  :on-remove="handleRemove"
                  :limit="1"
                  :file-list="fileList"
                  accept=".xlsx,.xls"
                  :auto-upload="true"
                >
                  <el-button slot="trigger" size="small" type="primary"
                    >上传文件</el-button
                  >
                  <div class="el-upload__tip" style="color: grey">
                    建议下载模板进行导入
                  </div>
                  <div class="el-upload__tip">1.仅支持上传.xls、.xlsx文件</div>
                  <div class="el-upload__tip">2.文件数据不能超过1000条</div>
                </el-upload>
              </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
              <el-button size="small" @click="cancelUpload()">取消</el-button>
              <el-button
                type="primary"
                size="small"
                @click="upload()"
                :disabled="uploading"
                >确定导入</el-button
              >
            </span>
          </el-dialog>
        </div>
      </div>
      <!-- 表格 -->
      <el-table :data="tableData" @selection-change="handleSelectionChange" stripe>
        <el-table-column type="index" label="序号" :index="indexMethod">
        </el-table-column>
        <el-table-column align="center" prop="rq" label="日期" width="100px">
        </el-table-column>
        <el-table-column prop="operaArea" label="作业区" align="center">
        </el-table-column>
        <el-table-column prop="zcb" label="注采班" align="center">
        </el-table-column>
        <el-table-column prop="psj" label="配注（水）间" align="center">
        </el-table-column>
        <el-table-column prop="poundSign" label="井号" align="center">
        </el-table-column>
        <el-table-column
          prop="proTime"
          label="生产时间（h:min）"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="injectMethod" label="注入方式" align="center">
        </el-table-column>
        <el-table-column
          prop="pressValue"
          label="允许注入压力（MPa）"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="zrsj" label="昨日数据" align="center">
          <el-table-column
            prop="zrsjZsyl"
            label="注水压力（MPa）"
            align="center"
          >
            <el-table-column prop="zrzsylBy" label="泵压" align="center">
            </el-table-column>
            <el-table-column prop="zrzsylYy" label="油压" align="center">
            </el-table-column>
            <el-table-column prop="zrzsylTy" label="套压" align="center">
            </el-table-column>
          </el-table-column>
          <el-table-column
            prop="zrsj_sbds"
            label="水表读数（m3）"
            align="center"
          >
            <el-table-column prop="zrsbdsStart" label="始" align="center">
            </el-table-column>
            <el-table-column prop="zrsbdsEnd" label="终" align="center">
            </el-table-column>
          </el-table-column>
          <el-table-column prop="zrrzrl" label="日注入量(m3/d)" align="center">
          </el-table-column>
          <el-table-column prop="zrrpzl" label="日配注量(m3/d)" align="center">
          </el-table-column>
        </el-table-column>
        <el-table-column prop="jrsj" label="今日数据" align="center">
          <el-table-column
            prop="jrsjZsyl"
            label="注水压力（MPa）"
            align="center"
          >
            <el-table-column prop="zsylBy" label="泵压" align="center">
            </el-table-column>
            <el-table-column prop="zsylYy" label="油压" align="center">
            </el-table-column>
            <el-table-column prop="zsylTy" label="套压" align="center">
            </el-table-column>
          </el-table-column>
          <el-table-column label="水表读数（m3）" align="center">
            <el-table-column prop="sbdsStart" label="始" align="center">
            </el-table-column>
            <el-table-column prop="sbdsEnd" label="终" align="center">
            </el-table-column>
          </el-table-column>
          <el-table-column prop="rzrl" label="日注入量(m3/d)" align="center">
          </el-table-column>
          <el-table-column prop="rpzl" label="日配注量(m3/d)" align="center">
          </el-table-column>
        </el-table-column>
        <el-table-column prop="cz" label="今日与昨日数据差值" align="center">
          <el-table-column prop="czZsyl" label="注水压力（MPa）" align="center">
            <el-table-column prop="jzrzsylBy" label="泵压" align="center">
            </el-table-column>
            <el-table-column prop="jzrzsylYy" label="油压" align="center">
            </el-table-column>
            <el-table-column prop="jzrzsylTy" label="套压" align="center">
            </el-table-column>
          </el-table-column>
          <el-table-column prop="jzrzrl" label="日注入量(m3/d)" align="center">
          </el-table-column>
          <el-table-column prop="jzrpzl" label="日配注量(m3/d)" align="center">
          </el-table-column>
        </el-table-column>
        <el-table-column label="今日" align="center">
          <el-table-column prop="byYy" label="泵压-油压（MPa）" align="center">
          </el-table-column>
        </el-table-column>
        <el-table-column prop="bz" label="备注" width="100" align="center">
        </el-table-column>

        <el-table-column
          align="center"
          fixed="right"
          prop="approveStatus"
          label="审核状态"
        >
          <template slot-scope="scope">
            <el-tooltip
              :content="scope.row.approveBz"
              placement="bottom"
              effect="light"
              :disabled="!scope.row.approveBz"
            >
              <el-badge
                :is-dot="scope.row.approveBz || scope.row.approveBz === ' '"
                class="item"
              >
                <el-tag
                  :class="scope.row.approveBz ? 'tagstyle' : ''"
                  :type="
                    scope.row.approveStatus == '2'
                      ? 'success'
                      : scope.row.approveStatus == '1'
                      ? 'warning'
                      : scope.row.approveStatus == '0'
                      ? 'info'
                      : 'danger'
                  "
                  disable-transitions
                  >{{
                    scope.row.approveStatus == "2"
                      ? "已通过"
                      : scope.row.approveStatus == "1"
                      ? "未审核"
                      : scope.row.approveStatus == "0"
                      ? "未提交"
                      : "未通过"
                  }}</el-tag
                >
              </el-badge>
            </el-tooltip>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          fixed="right"
          label="操作"
          width="140"
          v-if="
            hasPermission('sys:sjtb:dzyj:szhzrjscrbsj:edit') ||
            hasPermission('sys:sjtb:dzyj:szhzrjscrbsj:check')
          "
        >
          <template slot-scope="scope">
            <el-button
              @click="handleClick(scope.row, 'check')"
              type="text"
              v-if="hasPermission('sys:sjtb:dzyj:szhzrjscrbsj:check')"
              >查看</el-button
            >
            <el-button
              @click="handleClick(scope.row, 'edit')"
              type="text"
              v-if="hasPermission('sys:sjtb:dzyj:szhzrjscrbsj:edit')"
              >编辑</el-button
            >
            <el-button
              @click="handleDelete(scope.row)"
              type="text"
              style="color: red"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页器 -->
      <el-pagination
        align="right"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNo"
        :page-sizes="[1, 5, 10, 20, 30]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableData.length"
      >
      </el-pagination>
    </div>

    <!-- 弹出框 -->
    <el-dialog
      :title="myDialogTitle"
      :visible.sync="dialogFormVisible"
      :before-close="handleClose"
    >
      <el-form
        :inline="true"
        :model="szhzrjForm"
        class="demo-form-inline"
        ref="szhzrjForm"
        :disabled="isInput"
      >
        <!-- <el-divider content-position="left">基础信息</el-divider> -->
        <el-row>
          <el-col :span="6">
            <el-form-item label="日期:">
              <el-date-picker
                v-model="szhzrjForm.rq"
                type="date"
                placeholder="请选择日期"
                :picker-options="pickerOptions"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="作业区:">
              <el-select
                v-model="szhzrjForm.operaArea"
                placeholder="请选择作业区"
                clearable
              >
                <el-option
                  v-for="item in zyqOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="注采班:">
              <el-select
                v-model="szhzrjForm.zcb"
                placeholder="请选择注采班"
                clearable
              >
                <el-option
                  v-for="item in zcbOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-divider content-position="left">生产信息</el-divider>

        <el-row>
          <el-col :span="12">
            <el-form-item label="配注（水）间:">
              <el-input
                v-model="szhzrjForm.psj"
                placeholder="请输入配注（水）间"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="井号:">
              <el-input
                v-model="szhzrjForm.poundSign"
                placeholder="请输入井号"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="注入方式:">
              <el-input
                v-model="szhzrjForm.injectMethod"
                placeholder="请输入注入方式"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="允许注入压力(MPa)：">
              <el-input
                v-model="szhzrjForm.pressValue"
                placeholder="请输入请输入允许注入压力"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="生产时间(h:min):">
              <el-input
                v-model="szhzrjForm.proTime"
                placeholder="请输入生产时间"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="left">今日数据</el-divider>
        <el-row>
          <el-col :span="8">
            <el-form-item label="注水泵压(MPa):">
              <el-input
                v-model="szhzrjForm.zsylBy"
                placeholder="请输入注水泵压"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="注水油压(MPa):">
              <el-input
                v-model="szhzrjForm.zsylYy"
                placeholder="请输入注水油压"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="注水套压(MPa):">
              <el-input
                v-model="szhzrjForm.zsylTy"
                placeholder="请输入注水套压"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="水表开始读数:">
              <el-input
                v-model="szhzrjForm.sbdsStart"
                placeholder="请输入水表开始读数"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="水表结束读数:">
              <el-input
                v-model="szhzrjForm.sbdsEnd"
                placeholder="请输入水表结束读数"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="日注入量(m3/d):">
              <el-input
                v-model="szhzrjForm.rzrl"
                placeholder="请输入日注入量"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="日配注量(m3/d):">
              <el-input
                v-model="szhzrjForm.rpzl"
                placeholder="请输入日配注量"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="left">今日与昨日数据差值</el-divider>
        <el-row>
          <el-col :span="8">
            <el-form-item label="注水泵压(MPa):">
              <el-input
                v-model="szhzrjForm.jzrzsylBy"
                placeholder="请输入注水泵压"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="注水油压(MPa):">
              <el-input
                v-model="szhzrjForm.jzrzsylYy"
                placeholder="请输入注水油压"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="注水套压(MPa):">
              <el-input
                v-model="szhzrjForm.jzrzsylTy"
                placeholder="请输入注水套压"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="日注入量(m3/d):">
              <el-input
                v-model="szhzrjForm.jzrzrl"
                placeholder="请输入日注入量"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="日配注量(m3/d):">
              <el-input
                v-model="szhzrjForm.jzrpzl"
                placeholder="请输入日配注量"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="泵压-油压(MPa):">
              <el-input
                v-model="szhzrjForm.byYy"
                placeholder="请输入泵压与油压的差值"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" v-show="!ischeck">
        <el-button @click="close('szhzrjForm')">取 消</el-button>
        <el-button type="primary" @click="submitForm('szhzrjForm')"
          >确 定</el-button
        >
      </div>
      <div slot="footer" class="dialog-footer" v-show="ischeckSh">
        <el-button type="primary" @click="submitSh('szhzrjForm')"
          >提交审核</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";
import szhzrjApi from "@/api/szhzrjscrbsj";
import { getToken } from "@/utils/auth";
export default {
  name: "TimeView",
  created() {
    this.currentTime();
  },
  data() {
    return {
      pageNo: 1, //当前页码
      pageSize: 10, //每页显示数量
      total: 0, //总数量
      // table数据
      tableData: [],
      //当前时间
      nowDate: "",
      //表单填报的数据
      szhzrjForm: {
        rq: "",
        id: "",
        operaArea: "", //作业区
        zcb: "", //注采班
        psj: "", //配注间
        poundSign: "", //井号
        scsj: "", //生产时间
        proTime: "", //注入方式
        pressValue: "", //允许注入压力
        zrzsylBy: "", //昨日数据-注水压力-泵压
        zrzsylYy: "", //昨日数据-注水压力-油压
        zrzsylTy: "", //昨日数据-注水压力-套压
        zrsbdsStart: "", //昨日数据-开始水表读数
        zrsbdsEnd: "", //昨日数据-结束水表读数
        zrsjRzrl: "", //昨日数据-日注入量
        zrsjRpzl: "", //昨日数据-日配注量
        jrsjZsylBy: "", //今日数据-注水压力-泵压
        jrsjZsylYy: "", //今日数据-注水压力-油压
        jrsjZsylTy: "", //今日数据-注水压力-套压
        sbdsStart: "", //今日数据-开始水表读数
        sbdsEnd: "", //今日数据-结束水表读数
        jrsjRzrl: "", //今日数据-日注入量
        jrsjRpzl: "", //今日数据-日配注量
        czZsylBy: "", //今日与昨日数据差值-注水压力-泵压
        czZsylYy: "", //今日与昨日数据差值-注水压力-油压
        czZsylTy: "", //今日与昨日数据差值-注水压力-套压
        czRzrl: "", //今日与昨日数据差值-日注入量
        czRpzl: "", //今日与昨日数据差值-日配注量
        jrCz: "", //今日与昨日数据差值-泵压与油压差值
        bz: "", //备注
      },
      // 下拉框的内容
      zyqOptions: [
        { value: "第 一 作业区", label: "第 一 作业区" },
        { value: "第 二 作业区", label: "第 二 作业区" },
        { value: "第 三 作业区", label: "第 三 作业区" },
        { value: "第 四 作业区", label: "第 四 作业区" },
      ],
      zcbOptions: [
        { value: "树322注采班", label: "树322注采班" },
        { value: "东163队注采班", label: "东163队注采班" },
        { value: "东164队注采班", label: "东164队注采班" },
        { value: "东165队注采班", label: "东165队注采班" },
      ],
      rqOptions: [
        { value: "1", label: "昨日数据" },
        { value: "2", label: "今日数据" },
      ],
      //时间快捷选择
      pickerOptions: {
        // disabledDate(time) {
        //   return time.getTime() > Date.now();
        // },
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            },
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            },
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            },
          },
        ],
      },
      //编辑框是否显示
      dialogFormVisible: false,
      //弹出框是否是查看
      ischeck: false,
      //控制查看时不可更改数据
      isInput: false,
      //弹出框是否有提交审核按钮
      ischeckSh: false,
      //弹出框标题
      myDialogTitle: "",

      file: null,
      //加载动画
      uploadLoading: false,
      //上传的文件列表
      fileList: [],
      //控制弹出框显示与否
      uploadShowDialog: false,
      //上传地址
      uploadURL: "",
      //loading加载中
      downloadLoading: "",
      importDialog: false,
      fileList: [],
      urlFile: "",
      uploading: true,
      token: "",
    };
  },
  created() {
    this.search();
  },
  mounted() {
    // this.filterTime();
    // this.token =
    //   "http://47.108.251.250:3296/api/szhzrj/downLoadExcel?token=" +
    //   getToken();
    // // this.initDate();
  },
  methods: {
    async search() {
      // this.szhzrjForm.currentPage = currentPage;
      // this.szhzrjForm.pageSize = pageSize;
      // 发送查询请求
      let res = await szhzrjApi.getDataList(this.pageNo, this.pageSize);
      //判断是否成功
      if (res.success) {
        console.log(res.data);
        //赋值
        this.tableData = res.data.records;
        //总数量
        this.total = res.data.total;
      }
    },
    onSubmit() {
      console.log("submit!");
    },
    //关闭对话框
    handleClose(done) {
      this.$refs["szhzrjForm"].clearValidate();
      done();
    },
    handleClose1(done) {
      this.urlFile = "";
      this.fileList = [];
      done();
    },
    //触发弹窗关闭
    close(formName) {
      this.dialogFormVisible = false;
      // 清空表单
      // this.$refs[formName].resetFields();
      // 清空表单校验，避免再次进来会出现上次校验的记录
      this.$refs[formName].clearValidate();
    },
    submitForm(formName) {
      //表单验证
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          let res = null;
          console.log(this.szhzrjForm.id + "111");
          //判断菜单ID是否为空
          if (this.szhzrjForm.id === "") {
            //  this.szhzrjForm.poundSign = '树57-斜60';
            //发送添加请求
            res = await szhzrjApi.addData(this.szhzrjForm);
          } else {
            //发送修改请求
            // this.szhzrjForm.jh = 2;
            // console.log(334345)
            this.szhzrjForm.approveStatus = 0;
            res = await szhzrjApi.updateData(this.szhzrjForm);
          }
          console.log(res);
          //判断是否成功
          if (res.success) {
            this.$message.success(res.message);
            //刷新
            this.search();
            //关闭窗口
            this.dialogFormVisible = false;
          } else {
            console.log(res);
            this.$message.error(res.message);
          }
        }
      });
    },
    async submitSh(formName) {
      let res = null;
      //发送修改请求
      this.szhzrjForm.approveStatus = 1;
      this.szhzrjForm.approveBz = "";
      // console.log(334345)
      res = await szhzrjApi.updateData(this.szhzrjForm);

      console.log(res);
      //判断是否成功
      if (res.success) {
        this.$message.success(res.message);
        //刷新
        this.search();
        //关闭窗口
        this.dialogFormVisible = false;
      } else {
        console.log(res);
        this.$message.error(res.message);
      }
    },
    handleClick(row, handle) {
      // console.log(row.approveStatus);
      this.dialogFormVisible = true;
      if (handle == "check") {
        this.myDialogTitle = "数字化注入井生产日报";
        if (row.approveStatus == 0) {
          this.ischeckSh = true;
        } else {
          this.ischeckSh = false;
        }
        this.ischeck = true;
        this.isInput = true; // 1.表单禁用
        // this.szhzrjForm = row
        this.$objCopy(row, this.szhzrjForm); //把当前要编辑的数据复制到数据域，给表单回显
        this.$message({ message: "成功打开", type: "success" });
      } else if (handle == "edit") {
        if (row.approveStatus != 2) {
          this.myDialogTitle = "数字化注入井生产日报编辑";
          this.ischeck = false;
          this.ischeckSh = false;
          this.isInput = false;
          this.$objCopy(row, this.szhzrjForm); //把当前要编辑的数据复制到数据域，给表单回显
        } else {
          this.dialogFormVisible = false;
          this.$message({ message: "已通过不可修改！", type: "error" });
        }
      } else if (handle == "add") {
        // this.szhzrjForm ={}
        this.$resetForm("szhzrjForm", this.szhzrjForm); //清空表单数据
        this.myDialogTitle = "数字化注入井生产日报填报";
        this.ischeck = false;
        this.ischeckSh = false;
        this.isInput = false;
      }
      // console.log(row);
    },
    uploadFiles() {
      this.importDialog = true;
      this.urlFile = "";
    },
    cancelUpload() {
      this.urlFile = "";
      this.fileList = [];
      this.importDialog = false;
    },
    //  监听改变
    handleChange(file, fileList) {
      this.fileList = fileList;
    },
    // 移除
    handleRemove(file, fileList) {
      this.fileList = fileList;
    },
    beforeAvatarUpload(file) {
      //1MB=1024*1024(1MB=1024KB 1KB=1024MB)
      const is10M = file.size / 1024 / 1024 < 10;
      //限制文件上传大小
      if (!is10M) {
        this.$message.error("上传图片大小不能超过 10MB!");
        return false;
      }
      return true;
    },
    // 自定义上传Excel方法
    httpRequest(param) {
      // console.log(param.file);
      this.uploading = true;
      const File = this.fileList[0].raw;
      // const File = param.file
      console.log(File);
      // console.log(this.fileList);
      let formData = new FormData();
      formData.append("myfile", File);
      console.log(formData.get("myfile"));

      axios({
        url: "http://47.108.251.250:3296/api/fileAbout/fileUpload",
        method: "post",
        headers: {
          token: getToken(),
          "Content-Type": "multipart/form-data",
        },
        data: formData,
      }).then(
        (response) => {
          if (response.data.success === true && response.data.data !== "") {
            console.log(response.data);
            this.urlFile = response.data.data;
            console.log(this.urlFile);
            this.$message.success(response.data.message);
            param.onSuccess();
            this.uploading = false;
          } else {
            this.$message.error("上传失败");
          }
        },
        (error) => {
          console.log(error);
          this.$message.error(response.data.message);
        }
      );
    },
    //文件导入
    upload() {
      let formData = new FormData();
      formData.append("filePath", this.urlFile);
      console.log(formData.get("filePath"));
      axios({
        url: "http://47.108.251.250:3296/api/zrjscrb/batchInput",
        method: "post",
        headers: {
          token: getToken(),
          "Content-Type": "multipart/form-data",
        },
        data: formData,
      }).then(
        (response) => {
          if (response.data.success === true) {
            console.log(response.data);
            this.$message.success(response.data.message);
            //刷新
            this.search();
            //关闭窗口
            this.importDialog = false;
            this.fileList = [];
          } else {
            this.$message.error("导入失败");
          }
        },
        (error) => {
          console.log(error);
          this.$message.error(response.data.message);
        }
      );
    },

    //下载模板
    handleDownload() {
      import("@/vendor/Export2Excel").then((excel) => {
        console.log(11111);
        const multiHeader = [
          [
            "日期",
            "公司",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "第一作业区",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "第二作业区",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "第三作业区",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "第四作业区",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "肇州",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "提捞作业区",
            "",
            "",
            "",
            "",
            "",
            "",
            "备注",
          ], //第一行
          [
            "",
            "产油",
            "",
            "",
            "",
            "",
            "",
            "拉油",
            "",
            "",
            "库存",
            "",
            "",
            "注水",
            "",
            "积压",
            "",
            "测压",
            "",
            "作业区",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "树322",
            "东12",
            "尚12",
            "作业区",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "东16",
            "",
            "东14",
            "",
            "作业区",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "树2",
            "101队",
            "",
            "树16",
            "作业区",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "树103",
            "树12",
            "徐30",
            "徐6",
            "榆二联",
            "",
            "",
            "",
            "末端接油量",
            "",
            "",
            "",
            "肇州一工区",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "肇州二工区",
            "",
            "",
            "",
            "",
            "",
            "",
            "",
            "作业区",
            "",
            "卸油点",
            "",
            "",
            "",
            "",
            "",
          ], //第二行
        ]; // 前两行的表头数据，二维数组，不够的用空白补全
        const header = [
          "",
          "井口产油",
          "末端微机",
          "计划产油",
          "核实产油",
          "公司外输",
          "二联外输",
          "拉油",
          "提捞",
          "落地油",
          "公司库存",
          "二联差值",
          "二联库存",
          "计划水量",
          "实际水量",
          "作业",
          "待作业",
          "油井",
          "水井",
          "计划产油",
          "实际产油",
          "计划注水",
          "实际注水",
          "日注水量",
          "作业积压",
          "待作业积压",
          "油井测压",
          "水井测压",
          "库存",
          "微机",
          "微机",
          "微机",
          "计划产油",
          "实际产油",
          "计划注水",
          "实际注水",
          "日注水量",
          "作业积压",
          "待作业积压",
          "油井测压",
          "水井测压",
          "库存",
          "微机",
          "污水处理",
          "382微机",
          "东14微机",
          "计划产油",
          "实际产油",
          "计划注水",
          "日注水量",
          "作业积压",
          "待作业积压",
          "油井测压",
          "水井测压",
          "库存",
          "产油量",
          "产油量",
          "C02注入量",
          "微机",
          "计划产油",
          "实际产油",
          "计划注水",
          "实际注水",
          "日注水量",
          "作业积压",
          "待作业积压",
          "油井测压",
          "水井测压",
          "库存",
          "微机",
          "微机",
          "微机",
          "微机",
          "二联接油",
          "输差",
          "电脱",
          "污水",
          "实验站",
          "东16",
          "树8",
          "树127",
          "计划产油",
          "实际产油",
          "计划注水",
          "日注水量",
          "作业积压",
          "待作业积压",
          "油井测压",
          "水井测压",
          "计划产油",
          "实际产油",
          "计划注水",
          "日注水量",
          "作业积压",
          "待作业积压",
          "油井测压",
          "水井测压",
          "计划捞油",
          "实际捞油",
          "东16",
          "树8",
          "捞油合计",
          "新井捞油",
          "落地油",
          "",
        ]; // 最后一行的表头数据
        const filterVal = [
          "rq",
          "gsCsJkcy",
          "gsCsMdwj",
          "gsCsJhcy",
          "gsCsHscy",
          "gsCsGsws",
          "gsCsElws",
          "gsLyLy",
          "gsLyTl",
          "gsLyLdy",
          "gsKcGskc",
          "gsKcElcz",
          "gsKcElkc",
          "gsZsJhzs",
          "gsZsSjsl",
          "gsJyZy",
          "gsJyDzy",
          "gsCyYj",
          "gsCySj",
          "dyzyqZyqJhcy",
          "dyzyqZyqSjcy",
          "dyzyqZyqJhzs",
          "dyzyqZyqRzsl",
          "dyzyqZyqZyjy",
          "dyzyqZyqDzyjy",
          "dyzyqZyqYjcy",
          "dyzyqZyqShjcy",
          "dyzyqZyqKc",
          "dyzyqS322Wj",
          "dyzyqD12Wj",
          "dyzyqS12Wj",
          "dezyqZyqJhcy",
          "dezyqZyqSjcy",
          "dezyqZyqJhzs",
          "dezyqZyqRzsl",
          "dezyqZyqZyjy",
          "dezyqZyqDzyjy",
          "dezyqZyqYjcy",
          "dezyqZyqShjcy",
          "dezyqZyqKc",
          "dezyqD16Wj",
          "dezyqD16Wscl",
          "dezyqD14382wj",
          "deyzyqD14D14wj",
          "dszyqZyqJhcy",
          "dszyqZyqSjcy",
          "dszyqZyqJhzs",
          "dszyqZyqRzsl",
          "dszyqZyqZyjy",
          "dszyqZyqDzyjy",
          "dszyqZyqYjcy",
          "dszyqZyqShjcy",
          "dszyqZyqKc",
          "dszyqS2Cyl",
          "dszyq101dCyl",
          "dszyq101dZrl",
          "dszyqS16Wj",
          "dsizyqZyqJhcy",
          "dsizyqZyqSjcy",
          "dsizyqZyqJhzs",
          "dsizyqZyqRzsl",
          "dsizyqZyqZyjy",
          "dsizyqZyqDzyjy",
          "dsizyqZyqYjcy",
          "dsizyqZyqShjcy",
          "dsizyqZyqKc",
          "dsizyqS103Wj",
          "dsizyqS12Wj",
          "dsizyqX30Wj",
          "dsizyqX6Wj",
          "dsizyqYelEljy",
          "dsizyqYelSc",
          "dsizyqYelDt",
          "dsizyqYelWs",
          "dsizyqMdjylSyz",
          "dsizyqMdjylD16",
          "dsizyqMdjylS8",
          "dsizyqMdjylS127",
          "zzZyJhcy",
          "zzZySjcy",
          "zzZyJhzs",
          "zzZyRzsl",
          "zzZyZyjy",
          "zzZyDzyjy",
          "zzZyYjcy",
          "zzZyShjcy",
          "zzZeJhcy",
          "zzZeSjcy",
          "zzZeJhzs",
          "zzZeRzsl",
          "zzZeZyjy",
          "zzZeDzyjy",
          "zzZeYjcy",
          "zzZeShjcy",
          "tlzyqZyqJhly",
          "tlzyqZyqSjly",
          "tlzyqXydD16",
          "tlzyqXydS18",
          "tlzyqXydLyhj",
          "tlzyqXydXjly",
          "tlzyqXydLdy",
          "bz",
        ];
        const list = this.tableData;
        const data = this.formatJson(filterVal, list);
        const merges = [
          "A1:A3",
          "B1:S1",
          "T1:AE1",
          "AF1:AR1",
          "AS1:BE1",
          "BF1:BZ1",
          "CA1:CP1",
          "CQ1:CW1",
          "CX1:CX3",
          "B2:G2",
          "H2:G2",
          "K2:M2",
          "N2:O2",
          "P2:Q2",
          "R2:S2",
          "T2:AB2",
          "AF2:AN2",
          "AO2:AP2",
          "AQ2:AR2",
          "AS2:BA2",
          "BC2:BD2",
          "BF2:BN2",
          "BS2:BV2",
          "BW2:BZ2",
          "CA2:CH2",
          "CI2:CP2",
          "CQ2:CR2",
          "CS2:CW2",
        ]; // 合并单元格的数据
        excel.export_json_to_excel({
          multiHeader,
          header,
          merges,
          data,
        });
      });
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map((v) =>
        filterVal.map((j) => {
          return v[j];
        })
      );
    },
    getDate() {
      let date = new Date();
      let year = date.getFullYear(); // 年
      let month = date.getMonth() + 1; // 月
      let day = date.getDate(); // 日
      let week = date.getDay(); // 星期
      let weekArr = [
        "星期日",
        "星期一",
        "星期二",
        "星期三",
        "星期四",
        "星期五",
        "星期六",
      ];
      let hour = date.getHours(); // 时
      hour = hour < 10 ? "0" + hour : hour; // 如果只有一位，则前面补零
      let minute = date.getMinutes(); // 分
      minute = minute < 10 ? "0" + minute : minute; // 如果只有一位，则前面补零
      let second = date.getSeconds(); // 秒
      second = second < 10 ? "0" + second : second; // 如果只有一位，则前面补零
      this.nowDate = `${year}年${month}月${day}日 ${hour}时${minute}分${second}秒 ${weekArr[week]}`;
    },
    //定时器调取当前时间
    currentTime() {
      setInterval(() => {
        this.getDate();
      }, 1000);
    },
    onSubmit() {
      console.log("submit!");
    },

    uploadData() {
      console.log("批量导入成功");
    },
    //每页条数改变时触发 选择一页显示多少行
    handleSizeChange(size) {
      console.log(size);
      this.pageSize = size;
      this.search(this.pageNo, size);
    },
    //当前页改变时触发 跳转其他页
    handleCurrentChange(page) {
      console.log(page);
      this.pageNo = page;
      //调用查询方法
      this.search(page, this.pageSize);
    },
    // 序号计算
    indexMethod(index) {
      // index默认在0开始，这里+1
      return index + 1 + (this.pageNo - 1) * this.pageSize;
    },
    //复选框
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    async handleDelete(row) {
      //判断是否可以删除
      if (row.approveStatus == 2) {
        //提示不能删除
        this.$message({ message: "已通过不可删除！", type: "error" });
      } else {
        //确认是否删除
        let confirm = await this.$myconfirm("确定要删除该数据吗?");
        console.log(confirm);
        if (confirm) {
          //发送删除请求
          console.log("111");
          let res = await szhzrjApi.delete({ id: row.id });
          console.log("222");
          console.log(res);
          //判断是否成功
          if (res.success) {
            //成功提示
            this.$message.success(res.message);
            //刷新
            this.search();
          } else {
            //失败提示
            this.$message.error(res.message);
          }
        }
      }
    },
  },
};
</script>

<style lang="scss" scoped>
// 标题
.mytitle {
  font-size: large;
  padding-left: 10px;
  margin-bottom: 16px;
  float: left;
}

//按钮组
.myButtons {
  float: right;
}

//格子的样式
.bg-white {
  background: #ffffff;
}

.grid-content {
  padding: 10px;
  margin-bottom: 10px;
  border-radius: 4px;
}

.calendar ::v-deep .el-button-group::before {
  display: none;
}

.calendar ::v-deep .el-button-group::after {
  display: none;
}

// 分割线样式
.el-divider--horizontal {
  display: block;
  height: 2px;
  width: 100%;
  margin: 24px 0;
}

// 表单各项的样式
.el-form-item {
  margin: 15px 10px 15px 10px;
}

//表单禁用字体样式
.el-input.is-disabled ::v-deep .el-input__inner {
  color: #606266;
}
//对话框宽度
// .customWidth{
//         width:80%;
//     }
::v-deep .saveAsDialog {
  width: 60% !important;
}

::v-deep .el-table .cell {
  overflow: unset;
}

.el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 180px;
}

.el-input {
  width: 180px;
}
.tagstyle {
  cursor: pointer;
}
</style>